// 获取token中的user信息
// 用来判断一些非鉴权的接口是否为自己查询，比如获取用户信息

import jsonwebtoken from 'jsonwebtoken'
import { secret } from '../config.js'

export const getTokenUser = (ctx, next) => {
    const { authorization = '' } = ctx.request.header
    const token = authorization.replace('Bearer ', '')
    try {
        const user = jsonwebtoken.verify(token, secret)
        ctx.state.user = user
    } catch(err) {}

    next()
}